let regularMap = {
  mobile: {
    emptyMsg: '请输入手机号码',
    errorMsg: '手机格式不正确',
    reg: /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/
  },
  password: {
    emptyMsg: '请输入密码',
    errorMsg: '密码必须大于八位的，数字和字母组成',
    reg: /^[a-zA-Z\d_]{8,}$/
  },
}
/**
 * 手机校验
 * @param rule
 * @param value
 * @param callback
 */
let isMobile = (rule, value, callback) => {
  let result = regular(value, regularMap.mobile)
  if (result.valid) {
    callback()
  } else {
    callback(new Error(result.msg))
  }
};

/**
 * 手机校验
 * @param rule
 * @param value
 * @param callback
 */
let isPassword = (rule, value, callback) => {
  let result = regular(value, regularMap.password)
  if (result.valid) {
    callback()
  } else {
    callback(new Error(result.msg))
  }
};
function regular(value, regularData) {
  var data = {
    msg: '',
    valid: true
  }
  if (value === '') {
    data.msg = regularData.emptyMsg
    data.valid = false
  } else if (!regularData.reg.test(value)) {
    data.msg = regularData.errorMsg
    data.valid = false
  }
  return data
}

export default {
  isMobile,
  isPassword
}
